Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Passing "this" with bind returns undefined. Returning "this" returns windows object
  class ObjectMapping {
    constructor(value) {
        this.value = value;
    }
      map(func) {
        let b = func.bind(this)()
        console.log(b);
    }
  }
  
  const m = new ObjectMapping({ abc: 'abc',
      def: 'def' });
  const func = (value) => {
      return this[value]
  };
  
  m.map(func);

The func function is part of my assignment so it can't be changed but I can mess around with it to see what it returns.

const func = (value) => {
    return this //returns windows object
};

When I set it to just this, I get back the windows object regardless of what I pass in.

const func = (value) => {
    return value //returns undefined
};

When I bind it, it returns undefined.

map(func) {
   let key = Object.keys(this.value)[0] //key = abc
   let b = func(key)
   console.log(b);
}
const func = (value) => {
    return this.value
};

I tried passing in the the key but I still get undefined. How do I pass in an object and not get back the windows object?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda